package LeetCode.leetcode977;

public class Review5 {
    public int[] sortedSquares(int[] nums) {
        int l = 0, r = nums.length-1;
        int[] res = new int[nums.length];
        int rIndex = nums.length-1;
        while(l <= r){
            int rightQ = nums[r] * nums[r];
            int leftQ = nums[l] * nums[l];
            if(rightQ >= leftQ){
                res[rIndex--] = rightQ;
                r--;
            }else{
                res[rIndex--] = leftQ;
                l++;
            }
        }
        return res;
    }
}
